package com.archstoday.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.archstoday.R;
import com.archstoday.entity.TopicDetailComentEntity;
import com.archstoday.utils.ToolUtils;
import com.base.utils.ImageUtil;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class CommentForTopicReplyAdapter extends BaseAdapter {

    private Context mContext;
    private List<TopicDetailComentEntity.DataModelXX.CommentsModel.DataModel.RepliesModel> mData;

    public CommentForTopicReplyAdapter(Context context, List<TopicDetailComentEntity.DataModelXX.CommentsModel.DataModel.RepliesModel> data) {
        mContext = context;
        mData = data;
    }

    @Override
    public int getCount() {
        if (mData == null) {
            return 0;
        }
        return mData.size();
    }

    @Override
    public TopicDetailComentEntity.DataModelXX.CommentsModel.DataModel.RepliesModel getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_comment_for_topic_reply, null);
            holder.headIcon = (CircleImageView) view.findViewById(R.id.item_my_head);
            holder.nameTv = (TextView) view.findViewById(R.id.item_my_name_tv);
            holder.timeTv = (TextView) view.findViewById(R.id.item_my_time_tv);
            holder.commentTv = (TextView) view.findViewById(R.id.item_my_comment_tv);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        ImageUtil.setCropBitmap(mContext, holder.headIcon,
                mData.get(i).getUserImg(), R.mipmap.user_header_icon);
        holder.nameTv.setText(mData.get(i).getUserName());
        holder.timeTv.setText(ToolUtils.getCreatTime
                (String.valueOf(mData.get(i).getCreateTime())));
        holder.commentTv.setText("@" + mData.get(i).getUserNameReplied() + " " + mData.get(i).getCommentText());

        return view;
    }

    class Holder {
        CircleImageView headIcon;
        TextView nameTv, timeTv, commentTv;
    }
}